package com.perfect.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.perfect.base.BaseService;
import com.perfect.dao.ReconciliationMapper;
import com.perfect.query.ReconciliationQuery;
import com.perfect.vo.Reconciliation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

@Service
public class ReconciliationService extends BaseService<Reconciliation,Integer> {

    @Resource
    private ReconciliationMapper reconciliationMapper;
    public Map<String, Object> ListSettle(ReconciliationQuery query) {

        String[] str = new String[2];
        String str1 = null;
        String str2 = null;

        if (!StringUtils.isBlank(query.getDisbursementTime())) {
            str = query.getDisbursementTime().split(" - ");
            str1 = str[0];
            str2 = str[1];
        }

        String billNumber = query.getBillNumber();

        Map<String,Object> result = new HashMap<String,Object>();
        PageHelper.startPage(query.getPage(),query.getLimit());
        PageInfo<Reconciliation> pageInfo =new PageInfo<Reconciliation>(reconciliationMapper.selectByParam(billNumber,query.getState(),str1,str2));
        result.put("count",pageInfo.getTotal());
        result.put("data",pageInfo.getList());
        result.put("code",0);
        result.put("msg","");
//        System.out.println(Arrays.toString(str));
//        System.out.println(str.length);
//        System.out.println(billNumber);
//        System.out.println(str1);
//        System.out.println(str2);
        return result;
    }


    public Map<String, Object> ListReconciliation(ReconciliationQuery query) {
        String[] str = new String[2];
        String str1 = null;
        String str2 = null;

        if (!StringUtils.isBlank(query.getDisbursementTime())) {
            str = query.getDisbursementTime().split(" - ");
            str1 = str[0];
            str2 = str[1];
        }

        String billNumber = query.getBillNumber();

        Map<String,Object> result = new HashMap<String,Object>();
        PageHelper.startPage(query.getPage(),query.getLimit());
        PageInfo<Reconciliation> pageInfo =new PageInfo<Reconciliation>(reconciliationMapper.selectByParamSettle(billNumber,str1,str2));
        result.put("count",pageInfo.getTotal());
        result.put("data",pageInfo.getList());
        result.put("code",0);
        result.put("msg","");
//        System.out.println(Arrays.toString(str));
//        System.out.println(str.length);
//        System.out.println(billNumber);
//        System.out.println(str1);
//        System.out.println(str2);
        return result;
    }

}
